#include <assert.h>

#include <stack>

class MyQueue {
 public:
  MyQueue() = default;

  void push(int x) { input_.push(x); }

  int pop() {
    if (output_.empty()) {
      move_input_to_output();
    }
    int val = output_.top();
    output_.pop();
    return val;
  }

  int peek() {
    if (output_.empty()) {
      move_input_to_output();
    }
    return output_.top();
  }

  bool empty() { return input_.empty() && output_.empty(); }

 private:
  void move_input_to_output() {
    assert(output_.empty());

    while (!input_.empty()) {
      output_.push(input_.top());
      input_.pop();
    }
  }

 private:
  std::stack<int> input_;
  std::stack<int> output_;
};
